/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.hdasnvicpaul.entidad;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author WILLIAN
 */
@Entity
@Table(name = "SUCURSAL", catalog = "", schema = "HASP")
@NamedQueries({
    @NamedQuery(name = "Sucursal.findAll", query = "SELECT s FROM Sucursal s"),
    @NamedQuery(name = "Sucursal.findByCodigo", query = "SELECT s FROM Sucursal s WHERE s.sucursalPK.codigo = :codigo"),
    @NamedQuery(name = "Sucursal.findByInstitucion", query = "SELECT s FROM Sucursal s WHERE s.sucursalPK.institucion = :institucion"),
    @NamedQuery(name = "Sucursal.findByNomber", query = "SELECT s FROM Sucursal s WHERE s.nomber = :nomber")})
public class Sucursal implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SucursalPK sucursalPK;
    @Column(name = "NOMBER", length = 100)
    private String nomber;
    @JoinColumn(name = "INSTITUCION", referencedColumnName = "CODIGO", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Institucion institucion1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sucursal1")
    private List<Anciano> ancianoList;

    public Sucursal() {
    }

    public Sucursal(SucursalPK sucursalPK) {
        this.sucursalPK = sucursalPK;
    }

    public Sucursal(long codigo, long institucion) {
        this.sucursalPK = new SucursalPK(codigo, institucion);
    }

    public SucursalPK getSucursalPK() {
        return sucursalPK;
    }

    public void setSucursalPK(SucursalPK sucursalPK) {
        this.sucursalPK = sucursalPK;
    }

    public String getNomber() {
        return nomber;
    }

    public void setNomber(String nomber) {
        this.nomber = nomber;
    }

    public Institucion getInstitucion1() {
        return institucion1;
    }

    public void setInstitucion1(Institucion institucion1) {
        this.institucion1 = institucion1;
    }

    public List<Anciano> getAncianoList() {
        return ancianoList;
    }

    public void setAncianoList(List<Anciano> ancianoList) {
        this.ancianoList = ancianoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sucursalPK != null ? sucursalPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Sucursal)) {
            return false;
        }
        Sucursal other = (Sucursal) object;
        if ((this.sucursalPK == null && other.sucursalPK != null) || (this.sucursalPK != null && !this.sucursalPK.equals(other.sucursalPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.hdasnvicpaul.entidad.Sucursal[sucursalPK=" + sucursalPK + "]";
    }

}
